package com.eastjet.equipment.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eastjet.equipment.mapper.DeviceDeptMapper;
import com.eastjet.equipment.service.DeviceDeptService;
import com.eastjet.equipment.util.PageUtil;
import com.eastjet.equipment.util.RedisUtil;
import com.eastjet.maintenance.domain.DeviceDept;

import com.eastjet.maintenance.domain.DeviceExecution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 杨博文
* @description 针对表【device_dept(部门表)】的数据库操作Service实现
* @createDate 2024-11-25 09:23:37
*/
@Service
public class DeviceDeptServiceImpl extends ServiceImpl<DeviceDeptMapper, DeviceDept>
    implements DeviceDeptService {

    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private DeviceDeptMapper deviceDeptMapper;

    @Override
    public Page<DeviceDept>  getDeviceDept(int page, int size, String condition) {
        // 定义Redis中的键
        String redisKey = "DeviceDeptList:";
        System.out.println("DeviceDeptList-condition:"+condition);
        // 先查缓存Redis
        if (redisUtil.hasKey(redisKey)) {
            System.out.println(1);
            System.out.println("DeviceDeptList-从Redis中获取数据");
            List<DeviceDept> DeviceDeptList;
            if (condition != null  && !condition.isEmpty() && condition !="") {
                System.out.println(2);
                DeviceDeptList = deviceDeptMapper.selectByCondition(condition); // 获取所有数据
            } else {
                System.out.println(3);
                DeviceDeptList   = (List<DeviceDept>) redisUtil.get(redisKey);
            }
            // 使用PageUtil进行分页
            return PageUtil.paginate(DeviceDeptList, page, size);
        } else {
            System.out.println(4);
            System.out.println("在数据库中查询warehouseList");
            List<DeviceDept> DeviceDeptList;
            // 根据condition条件查询
            if (condition != null && !condition.isEmpty() && condition !="") {
                System.out.println(5);
                DeviceDeptList = deviceDeptMapper.selectByCondition(condition);
            } else {
                System.out.println(6);
                condition="";
                DeviceDeptList = deviceDeptMapper.selectByCondition(condition); // 获取所有数据
                // 将数据存入Redis
                redisUtil.set(redisKey, DeviceDeptList);
            }
            // 使用PageUtil进行分页
            return PageUtil.paginate(DeviceDeptList, page, size);
        }
    }
}




